package com.wuxiaolong.backend.controller;

import com.alibaba.fastjson.JSON;
import com.wuxiaolong.backend.entity.UserEntity;
import com.wuxiaolong.backend.model.JsonResult;
import com.wuxiaolong.backend.model.User;
import com.wuxiaolong.backend.util.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

import static com.wuxiaolong.backend.constant.Constants.TOKEN;

/**
 * Description:
 *
 * @author Leo
 * @date 2020-04-12
 */
@Slf4j
@RestController
public class LoginController {

    @ResponseBody
    @RequestMapping(value = {"/login","/"}, method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public JsonResult<Map<String,String>> login(@RequestHeader HttpHeaders httpHeaders, HttpServletRequest req, @RequestBody User params) {
        log.debug("登录请求，参数：{}", JSON.toJSONString(params));
        // todo

        String token= TokenUtil.sign(params);

        Map<String,String> result = new HashMap<>();
        result.put(TOKEN,token);

        return new JsonResult<Map<String,String>>(result);
    }
}
